import ResultWrapper = require('../ResultWrapper')
import RequestResult = require("../RequestResult")
import RequestListResult = require("../RequestListResult")
import BaseModel = require('../BaseModel')
import Product = require('../model/Product')
//code1

//code1

/**
 * 扫描条形码获取产品详情
 */
class StockApiBarcodeScan {
    
    get path(): string {
        return '/StockApi/barcodeScan'
    }
    
    get isUpload(): boolean {
        return false
    }

    setup(app: any, path: string) {
        console.log('setup service: /' + path)
    }

    //GET
    find(params: any, callback: Function) {
        return this.doWork(params.query)
    }

    doWork(params: any): Promise<any> {

        /**条码*/
        let barcode: string = params.barcode
        /**顾客角色：0.普通散客[默认]，1.批发商顾客*/
        let buyer_role: number = params.buyer_role


        let callback = (
            resolve: (data: RequestResult<Product>) => void, 
            reject: (error: Error) => void) => {

            let data = new Product()
            let result = ResultWrapper.wrap(data)
            result.message = '假数据'

//code2

//code2
            resolve(result)
        }
        return new Promise(callback)
    }
}

export = StockApiBarcodeScan